#ifndef HASIO_DETAIL_REACTIVE_SOCKET_SERVICE_HPP
#define HASIO_DETAIL_REACTIVE_SOCKET_SERVICE_HPP

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)

#include "reactive_socket_service_base.hpp"

namespace hasio {
namespace detail {

template <typename Protocol>
class reactive_socket_service
    : public reactive_socket_service_base
{
public:
    using protocol_type = Protocol;
    using endpoint_type = typename Protocol::endpoint;
    using handle_type = reactive_socket_service_base::handle_type;

    struct implementation_type
        : reactive_socket_service_base::implementation_type_base
    {

    };

    reactive_socket_service()
    {
    }
public:
    void listen(implementation_type &impl, 
        int backlog, hasio::error_code &ec)
    {
        socket_ops::listen(impl.socket_, backlog, ec);
    }

    void open(const Protocol &protocol, 
        hasio::error_code &ec)
    {
        socket_ops::socket(0,0,0, ec);
    }

    template <typename Socket>
    socket_type accept(implementation_type &impl,
        Socket &peer, endpoint_type *peer_endpoint, hasio::error_code &ec)
    {
        //socket_ops::accept(impl.socket_, peer_endpoint->data())
        return 0;
    }
    
    socket_type sync_accept() { return 0; }

    void non_blocking_accept(implementation_type &impl, 
        hasio::error_code &ec,
        socket_type &new_socket)
    {
        for (;;)
        {
            new_socket = socket_ops::accept(impl.socket_, nullptr, nullptr, ec);
            if (new_socket != 0)
            {
                return;
            }
        }
    }
};

}
}

#endif // HASIO_DETAIL_REACTIVE_SOCKET_SERVICE_HPP